<template>
  <div class="wrapper">
		<div class="header">申请加群问题</div>
		<div class="content">
			<div class="friend_img">
				<img :src="loginInfo.headurl" alt="">
			</div>
			<div class="user_info">
				<div class="user_underline">
					<div class="items_left">
						<span class="items_title">账号</span>
						<span class="items_text">{{loginInfo.identifier}}</span>
					</div>
					<!-- <div class="items_right"><i class="iconfont icon-dayuhao"></i></div> -->
				</div>
			</div>
			<div class="user_info">
				<div class="user_underline">
					<div class="items_left">
						<span class="items_title">昵称</span>
						<span class="items_text">{{loginInfo.identifierNick}}</span>
					</div>
					<!-- <div class="items_right"><i class="iconfont icon-dayuhao"></i></div> -->
				</div>
			</div>
			<div class="user_info2">
				<div class="user_underline">
					<div class="items_left">
						<span class="items_title">好友验证问题</span>
						<span class="items_text">请问你为什么要加入？</span>
					</div>
					<!-- <div class="items_right"><i class="iconfont icon-dayuhao"></i></div> -->
				</div>
				<div class="text_area">
					<textarea v-model="textArea"></textarea>
				</div>
			</div>
			<div class="check_btns">
				<button class="add_back">返回</button>
				<button class="add_friend" ref="sendBtn">提交申请</button>
			</div>
		</div>
	</div>
</template>
<script>
import Client from '../../config/common'
export default {
    data () {
      return {
         loginInfo: {},
				 textArea: '', // 申请加群回答问题的内容
				 applyGroupId: '' // 申请加入的群ID
      }
    },
    created () {

      // 登录初始化
      this.initLogin();
      
    },
    methods: {

      // 登录初始化
    initLogin(){
      Client.login(this.getLoginInfo);
    },

    // 获得登录成功信息
    getLoginInfo(loginInfo) {
      // 将 登录信息保存在 vue的data里
      this.loginInfo = loginInfo;
      Client.log("登录成功的信息-start");
      Client.log(this.loginInfo);
      Client.log("登录成功的信息-end");
			let That = this;
			
			// 申请加群的ID
			this.applyGroupId = Client.getQueryString("currentGroupId");
			console.log(this.applyGroupId);

			// 提交申请加群
			console.log();
			$(this.$refs.sendBtn).on("click", function(){
					That.applyJoinGroup();
			});
      
		},
		
		//申请加群
		applyJoinGroup() {
			let That = this;
				if (webim.Tool.getStrBytes($("#ajg_apply_msg").val()) > 300) {
						alert('您输入的附言超出限制(最长100个汉字)');
						return;
				}
				var options = {
						'GroupId': this.applyGroupId,
						'ApplyMsg': this.textArea,
						'UserDefinedField': ''
				};
				console.log(options);
				webim.applyJoinGroup(
						options,
						function(resp) {
							console.log("申请加入成功-start");
							console.log(resp);
							console.log("申请加入成功-start");
								// $('#apply_join_group_dialog').modal('hide');
								var joinedStatus = resp.JoinedStatus; //JoinedSuccess--成功加入，WaitAdminApproval--等待管理员审核
								if (joinedStatus == "JoinedSuccess") {
										//刷新我的群组列表
										//getJoinedGroupListHigh(getGroupsCallbackOK);
										alert('成功加入该群');
								} else {
										alert('申请成功，请等待群主审核');
										That.$router.push({path: '/groupList'});
								}
						},
						function(err) {
								alert(err.ErrorInfo);
						}
				);
		},
      
    }
}
</script>
<style lang="scss">
  @import '../../style/add_group_check';
</style>


